package com.zx.BookSeaReader.greendao.entity;

import org.greenrobot.greendao.annotation.Entity;
import org.greenrobot.greendao.annotation.Id;
import org.greenrobot.greendao.annotation.JoinEntity;
import org.greenrobot.greendao.annotation.ToMany;
import org.greenrobot.greendao.annotation.Transient;

import java.io.Serializable;
import java.util.List;
import org.greenrobot.greendao.annotation.Generated;
import org.greenrobot.greendao.DaoException;
import com.zx.BookSeaReader.greendao.gen.DaoSession;
import com.zx.BookSeaReader.greendao.gen.BookDao;
import com.zx.BookSeaReader.greendao.gen.BookCommentBeanDao;
import com.zx.BookSeaReader.greendao.gen.BookListBeanDao;
import com.zx.BookSeaReader.greendao.gen.UserBeanDao;

/**
 * @Author: ZX
 * @Time: 2020/3/27
 * @Description: 书单
 */
@Entity
public class BookListBean implements Serializable {
    @Transient
    private static final long serialVersionUID = 1L;

    @Id(autoincrement = true)
    private Long listId;
    private String title;//书单标题
    private String username;//书单作者
    private String desc;//书单简介
    private int collectorCount;//收藏数
    private String cover;//书单封面
    private int bookCount;//书籍数目
    private int bookindex;
    private boolean isRelease=false;//是否发表
    private String createTime;//创建时间
    @ToMany(referencedJoinProperty = "listId")
    private List<BookCommentBean> commentBeans;

    @ToMany
    @JoinEntity(
            entity = BookListCollect.class,
            sourceProperty = "bookListid",
            targetProperty = "bookid"
    )
    private List<Book> bookList;

    @ToMany
    @JoinEntity(
            entity = BookListSubscribe.class,
            sourceProperty = "bookListid",
            targetProperty = "userid"
    )
    private List<UserBean> userBeans;

    /** Used to resolve relations */
    @Generated(hash = 2040040024)
    private transient DaoSession daoSession;

    /** Used for active entity operations. */
    @Generated(hash = 894890804)
    private transient BookListBeanDao myDao;

    @Generated(hash = 1116917102)
    public BookListBean(Long listId, String title, String username, String desc, int collectorCount,
            String cover, int bookCount, int bookindex, boolean isRelease, String createTime) {
        this.listId = listId;
        this.title = title;
        this.username = username;
        this.desc = desc;
        this.collectorCount = collectorCount;
        this.cover = cover;
        this.bookCount = bookCount;
        this.bookindex = bookindex;
        this.isRelease = isRelease;
        this.createTime = createTime;
    }

    @Generated(hash = 1354382481)
    public BookListBean() {
    }

    public Long getListId() {
        return this.listId;
    }

    public void setListId(Long listId) {
        this.listId = listId;
    }

    public String getTitle() {
        return this.title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public String getUsername() {
        return this.username;
    }

    public void setUsername(String username) {
        this.username = username;
    }

    public String getDesc() {
        return this.desc;
    }

    public void setDesc(String desc) {
        this.desc = desc;
    }

    public int getCollectorCount() {
        return this.collectorCount;
    }

    public void setCollectorCount(int collectorCount) {
        this.collectorCount = collectorCount;
    }

    public String getCover() {
        return this.cover;
    }

    public void setCover(String cover) {
        this.cover = cover;
    }

    public int getBookCount() {
        return this.bookCount;
    }

    public void setBookCount(int bookCount) {
        this.bookCount = bookCount;
    }

    public int getBookindex() {
        return this.bookindex;
    }

    public void setBookindex(int bookindex) {
        this.bookindex = bookindex;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1242136701)
    public List<BookCommentBean> getCommentBeans() {
        if (commentBeans == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BookCommentBeanDao targetDao = daoSession.getBookCommentBeanDao();
            List<BookCommentBean> commentBeansNew = targetDao
                    ._queryBookListBean_CommentBeans(listId);
            synchronized (this) {
                if (commentBeans == null) {
                    commentBeans = commentBeansNew;
                }
            }
        }
        return commentBeans;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1651181967)
    public synchronized void resetCommentBeans() {
        commentBeans = null;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1733576052)
    public List<Book> getBookList() {
        if (bookList == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            BookDao targetDao = daoSession.getBookDao();
            List<Book> bookListNew = targetDao._queryBookListBean_BookList(listId);
            synchronized (this) {
                if (bookList == null) {
                    bookList = bookListNew;
                }
            }
        }
        return bookList;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1428566046)
    public synchronized void resetBookList() {
        bookList = null;
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#delete(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 128553479)
    public void delete() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.delete(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#refresh(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 1942392019)
    public void refresh() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.refresh(this);
    }

    /**
     * Convenient call for {@link org.greenrobot.greendao.AbstractDao#update(Object)}.
     * Entity must attached to an entity context.
     */
    @Generated(hash = 713229351)
    public void update() {
        if (myDao == null) {
            throw new DaoException("Entity is detached from DAO context");
        }
        myDao.update(this);
    }

    /** called by internal mechanisms, do not call yourself. */
    @Generated(hash = 986217926)
    public void __setDaoSession(DaoSession daoSession) {
        this.daoSession = daoSession;
        myDao = daoSession != null ? daoSession.getBookListBeanDao() : null;
    }

    public String getCreateTime() {
        return this.createTime;
    }

    public void setCreateTime(String createTime) {
        this.createTime = createTime;
    }

    /**
     * To-many relationship, resolved on first access (and after reset).
     * Changes to to-many relations are not persisted, make changes to the target entity.
     */
    @Generated(hash = 1707670271)
    public List<UserBean> getUserBeans() {
        if (userBeans == null) {
            final DaoSession daoSession = this.daoSession;
            if (daoSession == null) {
                throw new DaoException("Entity is detached from DAO context");
            }
            UserBeanDao targetDao = daoSession.getUserBeanDao();
            List<UserBean> userBeansNew = targetDao._queryBookListBean_UserBeans(listId);
            synchronized (this) {
                if (userBeans == null) {
                    userBeans = userBeansNew;
                }
            }
        }
        return userBeans;
    }

    /** Resets a to-many relationship, making the next get call to query for a fresh result. */
    @Generated(hash = 1681238678)
    public synchronized void resetUserBeans() {
        userBeans = null;
    }

    public boolean getIsRelease() {
        return this.isRelease;
    }

    public void setIsRelease(boolean isRelease) {
        this.isRelease = isRelease;
    }


}
